/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.scm.struts.actions;

import com.scm.hibernate.entities.Faculty;
import com.scm.struts.forms.EditFacultyForm;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author RANGER
 */
public class UpdateFacultyAction extends org.apache.struts.action.Action {

    /* forward name="success" path="" */
    private static String path;

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
          EditFacultyForm uff = (EditFacultyForm) form;
          System.out.println("Date of join = "+uff.getDateofjoin());
        // ArrayList<Student> li=(ArrayList<Student>)request.getSession().getAttribute("detail");

        Faculty f = new Faculty();
        f.setId(uff.getId());
        f.setFname(uff.getFname());
        f.setMname(uff.getMname());
        f.setLname(uff.getLname());
        f.setGender(uff.getGender());
        f.setEmail(uff.getEmail());
        f.setPassword("");
        f.setAddress(uff.getAddress());
        f.setCity(uff.getCity());
        f.setF_state(uff.getF_state());
        f.setContact(uff.getContact());
        f.setDateofbirth(uff.getDateofbirth());
        f.setDateofjoin(uff.getDateofjoin());
        f.setDesignation(uff.getDesignation());
        f.setQualification(uff.getQualification());
        // all left things
       
        if (f.update(uff.getId())) {
            List<Faculty> li = (List<Faculty>) request.getSession().getAttribute("faculty_viewlist");
            for (Faculty f1 : li) {
                if(f1.getId().equals(f.getId())){
                    f1.setId(f.getId());
                    f1.setFname(f.getFname());
                    f1.setLname(f.getLname());
                    f1.setAddress(f.getAddress());
                    f1.setContact(f.getContact());
                    f1.setEmail(f.getEmail());
                    f1.setPassword("");
                    f1.setDateofbirth(f.getDateofbirth());
                    f1.setDateofjoin(f.getDateofjoin());
                    f1.setGender(f.getGender());
                    f1.setCity(f.getCity());
                    f1.setF_state(f.getF_state());
                    f1.setMname(f.getMname());
                    System.out.println("i reached here");
                    f1.setDesignation(f.getDesignation());
                    f1.setQualification(f.getQualification());
                }
            }
            request.setAttribute("faculty_viewlist", li);

            path = "view_faculty";
        }

        return mapping.findForward(path);
    }
}

       

